package com.sy.simpleegg.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.sy.simpleegg.databinding.ItemIconPayBinding

class IconPayAdapter(
    private var mContext: Context,
    private var idOrUrlList: MutableList<Any>
) : RecyclerView.Adapter<IconPayAdapter.ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): IconPayAdapter.ViewHolder {
        val binding = ItemIconPayBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return ViewHolder(binding)
    }

    @SuppressLint("NewApi", "SetTextI18n", "UseCompatLoadingForDrawables")
    override fun onBindViewHolder(holder: IconPayAdapter.ViewHolder, position: Int) {
        val idOrUrl = idOrUrlList[position]
        Glide.with(holder.itemView)
            .load(idOrUrl)
            .fitCenter()
            .into(holder.icPay)
    }

    override fun getItemCount(): Int {
        return idOrUrlList.size
    }

    inner class ViewHolder(binding: ItemIconPayBinding) : RecyclerView.ViewHolder(binding.root) {
        val icPay: ImageView = binding.ivIc
    }
}